
# include "my_lib.h"
# include "studio_pid_c.h"



int main()
{
    double ini = 2, goal = 50, p = 0.5, i = 0.001, d = 0.6;
    studio_pid pid;

    // 初始化PID
    init_pid(&pid, ini, goal, p, i, d, 100, 200);

    // 第一阶段控制到 50
    double current_value = ini;
    for (int i = 0; i < 20; ++i)
    {
        double output = compute_pid(&pid, current_value);
        current_value += output; // 积分项和微分项会影响下一次计算
        printf("Step %d: 目标=%.2f, 当前值=%.2f, 输出=%.2f\n", i + 1, get_goal(&pid), current_value, output);
    }

    printf("到达目标值，开始第二阶段控制\n");
    // 改变目标值并重置PID状态
    set_goal(&pid, 100);

    // 第二阶段控制到 100
    for (int i = 0; i < 20; ++i)
    {
        double output = compute_pid(&pid, current_value);
        current_value += output; // 积分项和微分项会影响下一次计算
        printf("Step %d: 目标=%.2f, 当前值=%.2f, 输出=%.2f\n", i + 1, get_goal(&pid), current_value, output);
    }

    return 0;
}






